//
//  SPOrderTableViewCell.m
//  panzer
//
//  Created by 还带大道 on 2018/10/20.
//  Copyright © 2018年 还带大道. All rights reserved.
//

#import "SPOrderTableViewCell.h"
#import "SPGoodsModel.h"
#import "SPOrderListModel.h"

@interface SPOrderTableViewCell()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UIButton *handleBtn;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UIImageView *pic1;
@property (weak, nonatomic) IBOutlet UIImageView *pic2;
@property (weak, nonatomic) IBOutlet UIImageView *pic3;
@property (weak, nonatomic) IBOutlet UILabel *des1;
@property (weak, nonatomic) IBOutlet UIButton *moreBtn;


@end

@implementation SPOrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    _bgView.backgroundColor = [UIColor whiteColor];
    _bgView.layer.shadowColor = RZ_COLOR_ALPHA(226, 226, 226, 0.63).CGColor;
    _bgView.layer.cornerRadius = 8;
    _bgView.layer.shadowOffset = CGSizeMake(0,2);//shadowOffset阴影偏移,x向右偏移，y向下偏移，默认(0, -3)
    _bgView.layer.shadowOpacity = 1;//阴影透明度，默认0
    _bgView.layer.shadowRadius = 7;//阴影半径，默认3

    _handleBtn.layer.cornerRadius = 5;
    
}


-(void)setModel:(SPOrderListModel *)model
{
    _model = model;
    NSArray<SPGoodsModel *> *goods_list = model.goods_list;
    self.des1.text = [NSString stringWithFormat:@"共%ld件货品",goods_list.count];
    if(goods_list.count>=3){
        [self.pic1 sd_setImageWithURL:[NSURL URLWithString:goods_list[0].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        [self.pic2 sd_setImageWithURL:[NSURL URLWithString:goods_list[1].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        [self.pic3 sd_setImageWithURL:[NSURL URLWithString:goods_list[2].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        self.moreBtn.hidden = NO;
        
    }else if (goods_list.count==2){
        [self.pic1 sd_setImageWithURL:[NSURL URLWithString:goods_list[0].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        [self.pic2 sd_setImageWithURL:[NSURL URLWithString:goods_list[1].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        self.pic3.hidden = YES;
        self.moreBtn.hidden = YES;
        
    }else if (goods_list.count == 1){
        [self.pic1 sd_setImageWithURL:[NSURL URLWithString:goods_list[0].thumb] placeholderImage:[UIImage imageNamed:@"icon_goods"]];
        self.pic2.hidden = YES;
        self.pic3.hidden = YES;
        self.moreBtn.hidden = NO;
    }
    
    NSString *icon_name = nil;
    NSString *title = nil;
    if(model.status == 1){
        icon_name = @"icon_delivered";
        title = @"待发货";
        _time.hidden = NO;
    }else{
        icon_name = @"icon_exchange";
        title = @"售后处理";
        _time.hidden = YES;
    }
    _icon.image = [UIImage imageNamed:icon_name];
    _title.text = title;
}





- (IBAction)handleBtnOnClick:(UIButton *)sender {
    !self.handleBtnOnClickBlock?:self.handleBtnOnClickBlock(_model);
}

- (IBAction)moreBtnOnClick:(UIButton *)sender {
   !self.moreBtnOnClickBlock?:self.moreBtnOnClickBlock(_model);
}

@end
